﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Xml;

public partial class ws_Catalog_ADUsers : WSPageBase
{

    #region Page Events

    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
        // Enabled trace in code
        this.Context.Trace.IsEnabled = false;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        XmlDocument xReturn = getXML();
        Response.ContentType = "text/xml";
        Response.Write(xReturn.OuterXml);
    }

    #endregion

    #region Data

    public XmlDocument getXML()
    {
        XmlDocument xReturn = new XmlDocument();
        Ko2.Sys.AD o = new Ko2.Sys.AD();

        DataTable tbl = new DataTable("users");
        o.MakeTableUserExtProp(ref tbl);
        DataTable tbl1 = new DataTable("users1");
        DataTable tbl2 = new DataTable("users2");
        Exception err = o.GetUsersInOffice(ref tbl1, "Румянцево", true, true);
        if (err != null)
        {
            MakeXML(ref xReturn, ref tbl1, ref err);
            return xReturn;
        }
        err = o.GetUsersInNotOffice(ref tbl2, "Румянцево", true, true);
        if (err != null)
        {
            MakeXML(ref xReturn, ref tbl2, ref err);
            return xReturn;
        }

        foreach (DataRow r in tbl1.Rows)
        {
            DataRow newr = tbl.NewRow();
            foreach (DataColumn c in tbl1.Columns)
                newr[c.Caption] = r[c.Caption];
            tbl.Rows.Add(newr);
        }

        foreach (DataRow r in tbl2.Rows)
        {
            DataRow newr = tbl.NewRow();
            foreach (DataColumn c in tbl2.Columns)
                newr[c.Caption] = r[c.Caption];
            tbl.Rows.Add(newr);
        }

        MakeXML(ref xReturn, ref tbl, ref err);
        return xReturn;
    }

    #endregion

}
